let accountDetails = function(){
    let html = '<div style="margin-top: 10px;margin-right: 20px">\n' +
        '    <form class="layui-form" action="javascript:;" id="selectStockForm">\n' +
        '        <div class="layui-form-item">\n' +
        '            <div class="layui-inline">\n' +
        '                <label class="layui-form-label">用户id</label>\n' +
        '                <div class="layui-input-inline">\n' +
        '                    <select name="userId" id="userId" lay-filter="gameKind" lay-search="">\n' +
        '                    </select>\n' +
        '                </div>\n' +
        '            </div>\n' +
        '            <div class="layui-inline">\n' +
        '                <label class="layui-form-label">交易时间</label>\n' +
        '                <div class="layui-input-inline">\n' +
        '                    <select name="tradeTime" lay-search="">\n' +
        '                        <option value=""></option>\n' +
        '                        <option value="0">今天</option>\n' +
        '                        <option value="1">昨天</option>\n' +
        '                        <option value="2">一个月内</option>\n' +
        '                    </select>\n' +
        '                </div>\n' +
        '            </div>\n' +
        '            <div class="layui-inline">\n' +
        '                <label class="layui-form-label">交易类型</label>\n' +
        '                <div class="layui-input-inline">\n' +
        '                    <select name="tradeType" id="tradeType" lay-filter="tradeType">\n' +
        '                    </select>\n' +
        '                </div>\n' +
        '            </div>\n' +
        '                <div class="layui-inline">\n' +
        '                    <div class="layui-input-block">\n' +
        '                        <button class="layui-btn" lay-submit="" lay-filter="demo2">立即搜索</button>\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '        </div>\n' +
        '    </form>\n' +
        '</div>' +
        '<div style="margin-left: 10px;margin-right: 10px"><table class="layui-hide" id="test" lay-filter="test"></table></div>';
    layui.use(['table', 'form', 'jquery', 'element'], function () {
        var table = layui.table
            , form = layui.form
            , $ = layui.jquery
            , element = layui.element;

        $("#mainbody").html(html);
        //表格加载
        table.render({
            elem: '#test'
            , url: 'ftAccountDetails/get'
            , toolbar: 'toolbarDemo'
            , title: '明细表'
            , id: 'layuiTable' //用作主键 做刷新用
            , page: true
            , limit: 10//默认每页显示数量
            , limits: [10, 20, 30]//每页显示数量类型
            , cols: [[
                {type: 'checkbox'}
                , {type: 'numbers',title: '序号',width: 80}
                , {field: 'tradeTimeStr', title: '交易时间', width: 180, align: 'center'}
                , {field: 'userId', title: '用户id', width: 120, align: 'center'}
                , {field: 'expense', title: '支出', width: 120, align: 'center'}
                , {field: 'income', title: '收入', width: 150, align: 'center'}
                , {field: 'accountBalance', title: '账户金额', width: 150, align: 'center',sort: true}
                , {field: 'tradeTypeStr', title: '交易类型', width: 150, align: 'center'}
            ]]
        });

        //加载下家列表
        $.ajax({
            type: "POST",
            url: "lowers/get",
            dataType: "json",
            async:false,
            contentType: "application/json",
            success: function (list) {
                var str = '<option value=""></option>';
                for (var i = 0; i < list.length; i++) {
                    str += '<option value="' + list[i].username + '">' + list[i].username + '</option>';
                }
                $("#userId").html(str);

            },
            error: function () {
                console.log("获取下家列表失败！");
            }
        });

        //加载游戏分类
        $.ajax({
            type: "POST",
            url: "ftTradeType/get",
            dataType: "json",
            async:false,
            contentType: "application/json",
            success: function (list) {
                let str = '<option value=""></option>';
                for (let i = 0; i < list.length; i++) {
                    str += '<option value="' + list[i].id + '">' + list[i].tradeType + '</option>';
                }
                $("#tradeType").html(str);

            },
            error: function () {
                console.log("获取游戏分类列表失败！");
            }
        });



        form.render();


        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            switch (obj.event) {
                case 'add':
                    layer.open({
                        title: ['添加用户', 'font-size:18px;']
                        , shade: 0.6 //遮罩透明度
                        , area: ['630px','500px']//宽度
                        , type: 2
                        , anim: 1 //0-6的动画形式，-1不开启
                        , content: "/sys/user/addButton"
                        , success: function (layero, index) {
                            //layer高度自适应
                            // layer.iframeAuto(index);
                            table.reload('userTable');
                        }


                    })
                    break;
                case 'update':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else if (data.length > 1) {
                        layer.msg('只能同时编辑一个');
                    } else {
                        layer.open({
                            title: ['编辑用户', 'font-size:18px;']
                            , shade: 0.6 //遮罩透明度
                            , area: ['630px','500px']//宽度
                            , type: 2
                            , anim: 1 //0-6的动画形式，-1不开启
                            , content: "/sys/user/editButton/"+data[0].userId
                            , success: function (layero, index) {
                                //layer高度自适应
                                // layer.iframeAuto(index);
                                table.reload('userTable');
                            }
                            /*                           , end: function () {
                                                           var handle_status = $("#handle_status").val();
                                                           console.log(handle_status);
                                                           if (handle_status == 1) {

                                                               $("#handle_status").val("");
                                                               layer.msg('同上', {
                                                                   icon: 1,
                                                                   time: 1000 //2秒关闭（如果不配置，默认是3秒）
                                                               }, function () {
                                                                   table.reload('userTable');
                                                               });
                                                           } else if (handle_status == 2) {
                                                               layer.msg('编辑失败',
                                                                   {icon: 2, time: 1000}
                                                               )
                                                           }
                                                       }*/

                        })
                        break;
                    }
                    break;
                case 'delete':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else {
                        //页面删除效果
                        //$(".layui-form-checked").closest('tr[data-index]').remove();
                        var arr = new Array();
                        for (var i = 0; i < data.length; i++) {
                            arr.push(data[i].userId);
                        }
                        layer.confirm("确定删除吗?",{

                                btn: ['确定', '取消']
                                ,title:"提示"
                            }, function (index, layero) {
                                console.log(arr);
                                $.ajax({
                                    type: "POST",
                                    url: "/sys/user/delete",
                                    traditional: true,
                                    dataType: "json",
                                    contentType: "application/json",
                                    data: JSON.stringify(arr),
                                    success: function (data) {
                                        console.log(data);
                                        layer.msg("删除成功!",{ icon: 1, time: 1000 });
                                        table.reload('userTable');
                                    },
                                    error: function () {

                                        layer.msg(JSON.parse(data.responseText).message,{ icon: 1, time: 1000 });
                                    }
                                });
                            }
                        );

                    }
                    break;
            }
            ;
        });


        //监听搜索按钮
        form.on('submit(demo2)', function (data) {
            let tradeTime = data.field.tradeTime;
            let tradeType = data.field.tradeType;
            let userId = data.field.userId;
            let begin ;
            let end ;
            if(tradeTime == "0"){
                begin = new Date(new Date().toLocaleDateString()).getTime();
                end = begin+ 3600 * 1000 * 24;
            }else if(tradeTime == "1"){
                end = new Date(new Date().toLocaleDateString()).getTime();
                begin = end - 3600 * 1000 * 24;
            }else if(tradeTime == "2"){
                end = new Date(new Date().toLocaleDateString()).getTime();
                begin = end - 3600 * 1000 * 24 * 30;
            }
            table.reload('layuiTable', {
                where: {"begin": begin, "end": end, "userId": userId,"tradeType":tradeType}
            });

        });
        var handleSwitch = function (content, data, isChecked) {
            var tableDiv = $(data.othis);
            var tableId = tableDiv.parent().find("input").eq(0).val();
            var tableBut = tableDiv.find("em").html();
            var tableButId;
            if (tableBut=="ON"){
                tableButId = 0;
            }
            if (tableBut=="OFF") {
                tableButId = 1;
            }
            layer.open({
                content: content
                , btn: ['确定', '取消']
                , yes: function (index, layero) {
                    $.ajax({
                        url:'/sys/user/edit',
                        data:{
                            userId: tableId,
                            userStatus: tableButId
                        },
                        // dataType:'text',
                        type:'post',
                        success:function (data) {
                            console.log(data);
                            if (data == 'success'){
                                table.reload('userTable');
                            }else{
                                layer.msg('错误');
                            }
                        },
                        error: function (data) {

                            layer.msg(JSON.parse(data.responseText).message,{ icon: 1, time: 1000 });
                        }
                    });
                    data.elem.checked = isChecked;
                    form.render();
                    layer.close(layer.index);
                    //按钮【按钮一】的回调
                }
                , btn2: function (index, layero) {
                    //按钮【按钮二】的回调
                    data.elem.checked = !isChecked;
                    form.render();
                    layer.close(layer.index);
                    //return false 开启该代码可禁止点击该按钮关闭
                }
                , cancel: function () {
                    //右上角关闭回调
                    data.elem.checked = !isChecked;
                    form.render();
                    //return false 开启该代码可禁止点击该按钮关闭
                }
            });
            return false;
        }

    })
}
